{% extends "base_mobile.html" %}
{% load humanize %}

{% block title %}
CMAT 21 - {{event.shortcode}}
{% endblock title %}

{% block header %}
  <meta property='og:title' content='{{event.shortcode}} - CMAT 21 Scoreboard' />
  <meta property='og:description' content='{{event.event_type.name}} - {{event.level.name}} - {{event.gender.name}} - {{event.age_group.name}}.' />
{% endblock header %}

{% block heading %}
  {{event.shortcode}}
{% endblock heading %}

{% block event_li %}class="ui-btn-active"{% endblock %}

{% block content %}
<ul data-role="listview">
  <li data-theme="a">
    <h2><strong>{{event.level.name}} - {{event.gender.name}} - {{event.age_group.name}}</strong></h2>
    <p>{{event.event_type.name}}</p>
  </li>
  <li data-theme="a"><a href="/ring/{{event.ring.number}}">
    {% if event.completed %}
      Completed event in 
    {% else %}
      {% if event_order == 0 %}
        Current event in 
      {% else %}
        {% if event_order == 1 %}
          Next event in
        {% else %}
          {{event_order|ordinal}} event in
        {% endif %}
      {% endif %} 
    {% endif %}
    Ring {{event.ring.number}}
  </a></li>
  <li data-role="list-divider">
    <h2>Competitors</h2>
    <p class="ui-li-count">{{event.num_competitors}}</p>
  </li>
  {% for placing, meta in placings %}
    <li {% if event.completed %}data-theme="e"{% endif %}>
      <a href="/competitor/{{placing.competitor.last_name}}/{{placing.competitor.first_name}}">
        <h3>
          {{placing.competitor.first_name|lower|capfirst}} 
          {{placing.competitor.last_name|lower|capfirst}}
          {% if event.completed %}
            - {{placing.place|ordinal}} place
          {% else %}
            {% if placing.order %}
            - {{placing.order|ordinal}} in line
            {% endif %}
          {% endif %}
        </h3>
        {% if event.completed %}
          <p class="ui-li-count">{{placing.final_score|floatformat:2}}</p>
          {% if placing.scores %}
            <p><strong>Scores: 
              {% for score in meta.scores %}
                {% if score %}
                  {% if not forloop.first %}
                    - 
                  {% endif %}
                  {{score|floatformat:2}}
                {% endif %}
              {% endfor %}
            </strong></p>
          {% endif %}
          <p>Time: 
            {%if placing.time < 10 %}
              Not available
            {% else %}
              {{placing.time}} seconds
            {% endif %}
          </p>
          <p>
          {% if meta.time_deduct %}
            Time deductions: {{meta.time_deduct}}
            {% if meta.other_deduct %}
              - Other deductions: {{meta.other_deduct}}
            {% endif %}
          {% else %}
            {% if meta.other_deduct %}
              Other deductions: {{meta.other_deduct}}
            {% else %}
              No deductions
            {% endif %}
          {% endif %}
        {% endif %}
        </p>
      </a>
    </li>
  {% endfor %}
</ul>
{% endblock content %}
